package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.wx.footprint.WxFootPrintListInnerVo;
import com.cskaoyan.service.wx.WxFootPrintService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * /**
 *
 * @author xyh
 * @since 2022/11/23 11:31
 */
@RestController
@RequestMapping("wx/footprint")
public class WxFootPrintController {
    @Autowired
    WxFootPrintService wxFootPrintService;

    @RequestMapping("list")
    public BaseRespVo<CommonData<WxFootPrintListInnerVo>> list(Integer page, Integer limit) {
        // Session session = SecurityUtils.getSubject().getSession();
        // MarketUser info = (MarketUser) session.getAttribute("info");
        Subject subject = SecurityUtils.getSubject();
        MarketUser principal =(MarketUser) subject.getPrincipal();
        if (principal == null){
            return BaseRespVo.error(501,"请登录");
        }
        Integer userId = principal.getId();
        CommonData<WxFootPrintListInnerVo> list = wxFootPrintService.list(page, limit, userId);
        return BaseRespVo.ok(list);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map deleteMap) {
        // 首先要从里面获取id
        Integer id = (Integer) deleteMap.get("id");
        // 传入后端进行删除
        int code =wxFootPrintService.delete(id);
        return BaseRespVo.ok();
    }
}
